<?php
class InfoAction extends CommonAction {

	public function _before_insert()
    {
    	$_POST['ctime'] = time();
    }



	public function _before_add()
    {
		$this->getTypes();
		$this->getThemes();
    }

    public function _before_edit()
    {
		$this->getTypes();
		$this->getThemes();
    }

    function getTypes(){
    	$InfoType = M('InfoType');
    	$map['mid'] = $this->mid;
    	$map['url'] = array('eq',' ');
    	$types = $InfoType->where($map)->select();
	    $this->assign('types',$types);
    }

    
    function getThemes()
    {
    	$dir = './Tpl/Mobile/';
    	$dir_handle = opendir($dir);
    	$arr=array();  
    	if($dir_handle)  
	    {  
	        // 这里必须严格比较，因为返回的文件名可能是“0”   
	        while(($file=readdir($dir_handle))!==false)  
	        {  
	            if($file==='.' || $file==='..' || strtolower($file)=='index' )  
	                continue;  
	            if(is_dir($dir.'/'.$file)){
	            	if(!is_file($dir.'/'.$file.'/Info.html')) continue; 
	            	$v = array();
	                $v['tplname'] = $file;  
	                $v['preview'] = $dir.$file.'/Info.jpg';  
	                $arr[] = $v;
	            }
	        }  
	        closedir($dir_handle);  
	    } 
	    $this->assign('tpllist',$arr);
    }
}